﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FireStarter.Base;
using FireStarter.Base.BusinessObjectMerger;
using FireStarterModeller.BO;
using FireStarterModeller.Logic;
using Habanero.Base;
using NUnit.Framework;

namespace FireStarterModeller.Test.Logic
{
    [TestFixture]
    public class TestDMSolutionMerger
    {
        #region Setup/Teardown

        [TestFixtureSetUp]
        public virtual void TestFixtureSetup()
        {
            TestUtilsLogic.SetupFixture();
        }

        [SetUp]
        public virtual void SetupTest()
        {
            TestUtilsLogic.SetupTest();
        }

        [TearDown]
        public virtual void TearDownTest()
        {
        }

        #endregion

        [Test]
        public void Test_DMSolution()
        {
            //---------------Set up test pack-------------------
            DMSolution dmSolutionOriginal = TestUtilsShared.CreateSavedDMSolution();
            DMSolution dmSolutionNew = TestUtilsShared.CreateSavedDMSolution();
            BusinessObjectMerger merger = new BusinessObjectMerger(dmSolutionOriginal, null);
            string newName = dmSolutionNew.SolutionName;
            //---------------Execute Test ----------------------
            merger.Import(dmSolutionNew);
            //---------------Test Result -----------------------
            Assert.AreEqual(newName, dmSolutionOriginal.SolutionName);
            Assert.AreNotSame(dmSolutionNew, dmSolutionOriginal);
        }

        [Test]
        public void Test_DMSolution_WithNewClass()
        {
            //---------------Set up test pack-------------------
            DMSolution dmSolutionOriginal = TestUtilsShared.CreateSavedDMSolution();
            DMSolution dmSolutionNew = TestUtilsShared.CreateSavedDMSolution();
            DMClass newClass = TestUtilsDMClass.CreateSavedDMClass(dmSolutionNew);
            BusinessObjectMerger merger = new BusinessObjectMerger(dmSolutionOriginal, null);
            //-----------Assert preconditions-------------------
            Assert.AreEqual(0, dmSolutionOriginal.AllClasses.Count);
            //---------------Execute Test ----------------------
            merger.Import(dmSolutionNew);
            //---------------Test Result -----------------------
            Assert.AreEqual(1, dmSolutionOriginal.AllClasses.Count);
            Assert.AreSame(newClass, dmSolutionOriginal.AllClasses[0]);
        }
        
        [Test]
        public void Test_IgnoresGenerateCodeProperty()
        {
            //---------------Set up test pack-------------------
            
            DMSolution dmSolutionOriginal = TestUtilsShared.CreateSavedDMSolution();
            DMClass oldClass = TestUtilsDMClass.CreateSavedDMClass(dmSolutionOriginal);
            oldClass.GenerateCode = false;
            DMSolution dmSolutionNew = TestUtilsShared.CreateSavedDMSolution();
            DMClass newClass = TestUtilsDMClass.CreateSavedDMClass(dmSolutionNew);
            newClass.ClassNameBO = oldClass.ClassNameBO;
            newClass.GenerateCode = true;
            DMSolutionMerger merger = new DMSolutionMerger(dmSolutionOriginal);
            //---------------Execute Test ----------------------
            merger.Import(dmSolutionNew);
            //---------------Test Result -----------------------
            Assert.IsFalse(oldClass.GenerateCode);
        }
   
        [Test]
        public void Test_IgnoresNeedsRegenerationProperty()
        {
            //---------------Set up test pack-------------------
            
            DMSolution dmSolutionOriginal = TestUtilsShared.CreateSavedDMSolution();
            DMClass oldClass = TestUtilsDMClass.CreateSavedDMClass(dmSolutionOriginal);
            oldClass.NeedsRegeneration = true;
            DMSolution dmSolutionNew = TestUtilsShared.CreateSavedDMSolution();
            DMClass newClass = TestUtilsDMClass.CreateSavedDMClass(dmSolutionNew);
            newClass.ClassNameBO = oldClass.ClassNameBO;
            newClass.NeedsRegeneration = false;
            DMSolutionMerger merger = new DMSolutionMerger(dmSolutionOriginal);
            //---------------Execute Test ----------------------
            merger.Import(dmSolutionNew);
            //---------------Test Result -----------------------
            Assert.IsTrue(oldClass.NeedsRegeneration);
        }

    }

   
}
